<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 80px">订单号:</label>
        <div class="layui-input-inline" style="width:12%">
            <input type="text" name="billNo" id="billNo" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width:80px">民宿名称:</label>
        <div class="layui-input-inline" style="width:8%">
            <input type="text" name="hotelNickName" id="hotelNickName" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width:80px">用户手机:</label>
        <div class="layui-input-inline" style="width:8%">
            <input type="text" name="account" id="account" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 60px;margin-left: 5px">状态:</label>
        <div class="layui-input-inline" style="width: 6%">
            <select name="status" id="status">
                <option value="">全部</option>
                <option value="0">未处理</option>
                <option value="1">已处理</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 80px">创建时间:</label>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeSt" name="addTimeSt">
        </div>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeEt" name="addTimeEt">
        </div>
        <!--<label class="layui-form-label" style="width: 60px;margin-left: 5px">支付方式:</label>
        <div class="layui-input-inline" style="width: 6%">
            <select name="payment" id="payment">
                <option value="">全部</option>
                <option value="wechat">微信</option>
            </select>
        </div>-->
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <a id="down" class="layui-btn layui-btn-radius" download="手动取消退款订单.csv" href="#">导出</a>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var tableIns;
    var allStr;

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeSt', //指定元素
            format: 'yyyy-MM-dd'
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeEt', //指定元素
            format: 'yyyy-MM-dd'
        });
    });

    $('#down').on('click', function (aLink) {
        var table = layui.table;
        var tab = allStr;
        var str = "民宿名称,房间名称,用户手机,用户姓名,身份证,订单金额,退款金额,退款时间,订单编号,退款凭证号\n";
        $.each(tab, function (i, row) {
            str = str + row["hotelName"] + "," + row["homeName"] + "," +
                "" + row["account"] + "," + row["trueName"] + "," + "ID" + row["idCard"] + "," + row["billFee"] + "," + row["refundFee"] + "," + row["createTime"] + "," +
                "" + "SY" + row["billNo"] + "," + "SY" + row["refundNo"] + "\n";
        });
        str = encodeURIComponent(str);
        aLink.target.href = "data:text/csv;charset:utf-8,\ufeff" + str;
    });

    $(function () {
        tableIns = createTable({
            url: 'billRefundCancelList',
            cols: [[
                {
                    field: 'hotelName',
                    title: '民宿名称',
                    width: 150
                }, {field: 'homeName', title: '房间名称', width: 150}, {
                    field: 'account',
                    title: '用户手机',
                    width: 120
                }, {
                    field: 'trueName',
                    title: '用户姓名',
                    width: 120
                }, {
                    field: 'idCard',
                    title: '身份证',
                    width: 150
                }, {
                    field: 'billFee',
                    title: '订单金额',
                    width: 100
                }, {
                    field: 'refundFee',
                    title: '退款金额',
                    width: 100
                }, {field: 'createTime', title: '退款时间', width: 170}, {field: 'billNo', title: '订单编号', width: 220}
                , {field: 'refundNo', title: '退款凭证号', width: 250}, {
                    fixed: 'right',
                    title: '操作',
                    width: 200,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]], height: 'full-130'
        });

        $.post('/backend/security/billRefund/billRefundCancelList', {
            addTimeSt: t.format("yyyy-MM-dd")
        }, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
    })
    ;

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象

        if (layEvent === 'detail') { //查看
            openDialog({
                url: "/backend/security/bill/detail?id=" + data.id,
                area: ["95%", "95%"]
            });
        } else if (layEvent === 'refund') { //退款
            openDialog({
                url: "/backend/security/billRefund/detail?id=" + data.id + "&billFee=" + data.billFee,
                area: ["55%", "75%"]
            });
        }
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });

        $.post('/backend/security/billRefund/billRefundCancelList', {
            billNo: $("#billNo").val(),
            account: $("#account").val(),
            status: $("#status").val(),
            addTimeSt: $("#addTimeSt").val(),
            addTimeEt: $("#addTimeEt").val()
        }, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
        return false;
    });
</script>
<script type="text/html" id="paymentTpl">
    {{#  if(d.payment ==="wechat"){ }}
    <span>微信</span>
    {{#  } }}
</script>
<script type="text/html" id="opbar">
    {{# if(d.status==0){ }}
    <a class="layui-btn layui-btn-xs" lay-event="refund">退款</a>
    {{#  } else if(d.status ===1){ }}
    <span style="color: #56b02a;">已处理 </span>
    {{# } }}
</script>
</body>
</html>
